<?php
/**
 * 获取新闻相关信息
 * 以json方式返回
 * solosky <solosky772@qq.com>
 */

include_once("common.php");

$pre    = $config["DB_PREX"]; 
//输出当前新闻
 $cate = parseCategory(getVar($_GET, "category"));
 $page = getVar($_GET, "page", 1, "int");
 $limit = getVar($_GET, "limit", 10, "int");
 $total = getVar($_GET,"total",-1,"int");
 
 //如果没有传递总共的页数，查询之
 if($total==-1){
 	$sql = "SELECT COUNT(newshash) as t FROM {$pre}news WHERE categoryhash IN (".implode(",",$cate)." )";
 	$db->query($sql);
	$t = $db->getOneRow();
	$total = $t["t"];
 }
 $sql = "SELECT newshash,title,date,intro,thumb,media,image,view,dig FROM {$pre}news WHERE categoryhash IN (".implode(",",$cate)." ) ORDER BY date DESC LIMIT ".(($page-1)*$limit).", $limit";
 
 $db->query($sql);
 $rows = $db->getRows();
 $ret = array(
		"total" =>$total,
		"data" =>$rows
	);
 exit(json_encode($ret));


?>